﻿using MTQ.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace MTQ.Web
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        private string appPath = "";
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            appPath = Server.MapPath("/");

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(appPath + "bin\\log4net.config"));
            Common.LogManager.WriteLog("IIS Start");

            EmailService.ServerPath = Server.MapPath("/") + "Attachment\\";

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            desomething();
        }

        protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            setLanguage();
        }

        /// <summary>
        /// 语言设置
        /// </summary>
        private void setLanguage()
        {

            //if (HttpContext.Current.Session != null)
            //{
            //    CultureInfo ci = (CultureInfo)this.Session["CurrentLanguage"];
            //    if (ci == null)
            //    {
            //        ci = new CultureInfo("en-us");
            //        this.Session["CurrentLanguage"] = ci;
            //    }
            //    Thread.CurrentThread.CurrentUICulture = ci;
            //    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
            //}

        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            //if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
            //{
            //    //如何指向绝对路径的URL?
            //    //RedirectToRoute(new { controller = "Home", action = "Index" });//可跳出本controller
            //    Response.Redirect("/Home/Page404");
            //}
            //if (ex is Exception && ((Exception)ex).Message == "logintimeout")
            //{
            //    // Response.Redirect("/Home/Page404");
            //    // Response.Write("<script type='text/javascript'>alert('登录超时！请重新登录');</script>");
            //}
            Common.LogManager.WriteLog(ex.Message,ex);
        }

        public void desomething()
        {          



        }


    }
}